package com.ziven.common.widget.index;

import androidx.annotation.NonNull;

import com.ziven.easygo.util.Nulls;

/**
 * @author Ziven
 */
abstract class IndexInterfaceProxy implements IndexInterface {

    private IndexInterface indexInterface;

    public void setIndexInterface(@NonNull IndexInterface ii) {
        indexInterface = ii;
    }

    private Nulls<IndexInterface> getIndexInterfaceNulls() {
        return Nulls.of(indexInterface);
    }

    @Override
    public void setIndexGetData(@NonNull IndexGetData indexGetData) {
        getIndexInterfaceNulls().doNotNull(value -> value.setIndexGetData(indexGetData));
    }

    @Override
    public void setIndexCallback(@NonNull IndexCallback indexCallback) {
        getIndexInterfaceNulls().doNotNull(value -> value.setIndexCallback(indexCallback));
    }

    @Override
    public void removeIndexCallback(@NonNull IndexCallback indexCallback) {
        getIndexInterfaceNulls().doNotNull(value -> value.removeIndexCallback(indexCallback));
    }

    @Override
    public void notifyDataUpdated() {
        getIndexInterfaceNulls().doNotNull(IndexInterface::notifyDataUpdated);
    }

    @Override
    public void updateIndexName(int index, @NonNull String name) {
        getIndexInterfaceNulls().doNotNull(value -> value.updateIndexName(index, name));
    }
}
